﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace B2B.Models
{
    public class SP_QuoteSent
    {
        int maBaoGia;

        public int MaBaoGia
        {
            get { return maBaoGia; }
            set { maBaoGia = value; }
        }
        string tenSP;

        public string TenSP
        {
            get { return tenSP; }
            set { tenSP = value; }
        }
        string file;

        public string File
        {
            get { return file; }
            set { file = value; }
        }
        string link;

        public string Link
        {
            get { return link; }
            set { link = value; }
        }
        string emailNguoiNhan;

        public string EmailNguoiNhan
        {
            get { return emailNguoiNhan; }
            set { emailNguoiNhan = value; }
        }

        int tinhTrang;

        public int TinhTrang
        {
            get { return tinhTrang; }
            set { tinhTrang = value; }
        }

        private int maSPM;

        public int MaSPM
        {
            get { return maSPM; }
            set { maSPM = value; }
        }


        public ArrayList ds_BaoGiaGui(string emailNguoiGui, int page)
        {
            ArrayList list_BaoGia = new ArrayList();
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_BAOGIAGUI", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@EMAILNGUOIGUI", emailNguoiGui);
            cmd.Parameters.AddWithValue("@PAGECURENT", page);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                SP_QuoteSent quote = new SP_QuoteSent(); 
                quote.MaBaoGia = reader.GetInt32(0);
                quote.TenSP = reader.GetString(1);
                quote.File = reader.GetString(2);
                quote.Link = reader.GetString(3);
                quote.EmailNguoiNhan = reader.GetString(4);
                quote.TinhTrang = reader.GetInt32(5);
                list_BaoGia.Add(quote);
            }
            conn.Close();
            return list_BaoGia;
        }

        public int tongTrangBaoGiaGui(string email)
        {
            int tongBaoGiaGui = 0;
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_TONGBAOGIAGUI", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@EMAIL", email);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                tongBaoGiaGui = reader.GetInt32(0);
            }
            conn.Close();
            int tongtrang = tongBaoGiaGui / 10;
            if (tongBaoGiaGui % 10 != 0)
                tongtrang++;
            return tongtrang;
        }

        public int tongTrangBaoGiaGuiSPM(string email)
        {
            int tongBaoGiaGui = 0;
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_TONGBAOGIAGUISPM", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@EMAIL", email);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                tongBaoGiaGui = reader.GetInt32(0);
            }
            conn.Close();
            int tongtrang = tongBaoGiaGui / 10;
            if (tongBaoGiaGui % 10 != 0)
                tongtrang++;
            return tongtrang;
        }

        public ArrayList danhSachBaoGiaSPMGui(int page, string email)
        {
            ArrayList list_BaoGiaNhanSPM = new ArrayList();
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_BAOGIASPMGUI",conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@EMAIL", email);
            cmd.Parameters.AddWithValue("@PAGE", page);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                SP_QuoteSent quote = new SP_QuoteSent();
                quote.MaBaoGia = reader.GetInt32(0);
                quote.MaSPM = reader.GetInt32(1);
                quote.TenSP = reader.GetString(2);
                quote.File = reader.GetString(3);
                quote.EmailNguoiNhan = reader.GetString(4);
                quote.TinhTrang = reader.GetInt32(5);
                list_BaoGiaNhanSPM.Add(quote);
            }
            conn.Close();
            return list_BaoGiaNhanSPM;
        }

    }
}